package ru.chaykin.ui.swing.combobox;

import java.awt.Component;
import java.util.Locale;

import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.plaf.basic.BasicComboBoxRenderer;

import ru.chaykin.util.StringUtil;

@SuppressWarnings({ "serial", "rawtypes" })
public class LocaleComboBoxRenderer extends BasicComboBoxRenderer {

	@Override
	public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
		Component component = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
		if (value instanceof Locale && component instanceof JLabel) {
			String text = StringUtil.toUpperCaseFirstChar(((Locale)value).getDisplayLanguage());
			((JLabel)component).setText(text);
		}
		return component;
	}
}
